//
// Created by work on 24-8-23.
//

#ifndef IOT_PLAT_CVALUE_H
#define IOT_PLAT_CVALUE_H
#include <string>
#include <utility>
#include <dist/json/json.h>
#include <os/miscellany/date_time.h>
namespace iotplat {

    class CValue {
    public:
        enum EValueType{
            IOT_Int,
            IOT_String,
            IOT_Float,
            IOT_Bool,
            IOT_Json,
            IOT_DateTime,
            IOT_Map
        };
    public:
        [[maybe_unused]] explicit CValue(){
            m_valid = false;
        }

        [[maybe_unused]] explicit CValue(int value){
            v_i =  value;
            m_type = IOT_Int;
            m_valid = true;
        };

        [[maybe_unused]] explicit CValue(std::string value){
            v_s = std::move(value);
            m_type = IOT_String;
            m_valid = true;
        }

        [[maybe_unused]] explicit CValue(float value){
            v_f = value;
            m_type = IOT_Float;
            m_valid = true;
        }

        [[maybe_unused]] explicit CValue(bool value){
            v_b = value;
            m_type = IOT_Bool;
            m_valid = true;
        }

        [[maybe_unused]] explicit CValue(Json::Value value){
            v_json = std::move(value);
            m_type = IOT_Json;
            m_valid = true;
        }

        [[maybe_unused]] explicit CValue(CDateTime datetime){
            v_dt = datetime;
            m_type = IOT_DateTime;
            m_valid = true;
        }

        [[maybe_unused]] [[nodiscard]] inline int asInt() const {
            return v_i;
        }

        [[maybe_unused]] inline std::string asString(){
            return v_s;
        }

        [[maybe_unused]] [[nodiscard]] inline float asFloat() const{
            return v_f;
        }

        [[maybe_unused]] [[nodiscard]] inline bool asBool() const{
            return v_b;
        }

        inline Json::Value asJson(){
            return v_json;
        }

        inline CDateTime asDateTime(){
            return v_dt;
        }

        inline EValueType type() {
            return m_type;
            m_valid = true;
        }

        inline bool valid(){
            return m_valid;
            m_valid = true;
        }

    private:
        int v_i{};
        std::string v_s;
        float v_f{};
        bool v_b{};
        Json::Value v_json;
        CDateTime v_dt;

        bool m_valid = false;
        EValueType m_type;
    };

} // iotplat

#endif //IOT_PLAT_CVALUE_H
